Passed
Pull Request — master (#70)
by Mathieu
01:43
created

CreateQuoteAction   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 2
eloc 29
dl 0
loc 31
rs 10
c 0
b 0
f 0

1 Function

Rating   Name   Duplication   Size   Complexity  
A index 0 19 2
1
import {
2
  Body,
3
  Post,
4
  Controller,
5
  Inject,
6
  BadRequestException,
7
  UseGuards
8
} from '@nestjs/common';
9
import {AuthGuard} from '@nestjs/passport';
10
import {ApiUseTags, ApiBearerAuth, ApiOperation} from '@nestjs/swagger';
11
import {ICommandBus} from 'src/Application/ICommandBus';
12
import {LoggedUser} from 'src/Infrastructure/User/Decorator/LoggedUser';
13
import {User} from 'src/Domain/User/User.entity';
14
import {ActivityView} from 'src/Application/Activity/View/ActivityView';
15
import {IQueryBus} from 'src/Application/IQueryBus';
16
import {GetActivityByIdQuery} from 'src/Application/Activity/Query/GetActivityByIdQuery';
17
import {CreateQuoteCommand} from 'src/Application/Billing/Command/CreateQuoteCommand';
18
import {QuoteDTO} from './DTO/QuoteDTO';
19
20
@Controller('quotes')
21
@ApiUseTags('Billing')
22
@ApiBearerAuth()
23
@UseGuards(AuthGuard('bearer'))
24
export class CreateQuoteAction {
25
  constructor(
26
    @Inject('ICommandBus')
27
    private readonly commandBus: ICommandBus,
28
    @Inject('IQueryBus')
29
    private readonly queryBus: IQueryBus
30
  ) {}
31
32
  @Post()
33
  @ApiOperation({title: 'Create new quote'})
34
  public async index(@Body() quoteDto: QuoteDTO, @LoggedUser() user: User) {
35
    try {
36
      const {date, projectId, customerId, expiryDate} = quoteDto;
37
      const id = await this.commandBus.execute(
38
        new CreateQuoteCommand(
39
          user,
40
          new Date(date),
41
          new Date(expiryDate),
42
          customerId,
43
          projectId
44
        )
45
      );
46
47
      return id;
48
    } catch (e) {
49
      throw new BadRequestException(e.message);
50
    }
51
  }
52
}
53